﻿<script src="http://code.jquery.com/jquery-1.4.3.min.js" type="text/javascript"></script>
<style>
    /* css pour la tooltip lien avec preview */
    #screenshot
    {
        position: absolute;
        border: 1px solid #ccc;
        background: #333;
        padding: 5px;
        display: none;
        color: #fff;
    }
    /* css pour la tooltip image preview */
    #preview
    {
        position: absolute;
        border: 1px solid #ccc;
        background: #333;
        padding: 5px;
        display: none;
        color: #fff;
    }
    /* css pour la tooltip normal */
    #tooltip
    {
        position: absolute;
        border: 1px solid #333;
        background: #f7f5d1;
        padding: 2px 5px;
        color: #333;
        display: none;
    }
</style>
<script type="text/javascript">
    // Define the entry point
    $(document).ready(function () {
        // The DOM (document object model) is constructed
        // We will initialize and run our plugin here
        IcoToThumbs();
        MakeTable();
         imagePreview();
    });

    this.MakeTable = function () {

        var result = $('#CSR.srch-WPBody .srch-results');
        var tbl = $('<table></table>');

        var icon = $('.srch-Icon');
        icon.each(
        function (index) {
            $(this).css('float','right');
            var srchTitle2 = $(this).nextAll('.srch-Title2:first');
            var srchDesc2 = $(this).nextAll('.srch-Description2:first');
            var srchMeta2 = $(this).nextAll('.srch-Metadata2:first');
            var srchMeta1 = $(this).nextAll('.srch-Metadata1:first');
            var row = $('<tr/>');
            tbl.append(row);
            var cell1 = $('<td valign=\'top\' wisth=\'1px\' align=\'Right\'/>');
            row.append(cell1);
            cell1.append(this);
            var cell2 = $('<td/>');
            row.append(cell2);
            cell2.append(srchTitle2);
            cell2.append(srchDesc2);
            cell2.append(srchMeta2);
            cell2.append(srchMeta1);


        });
        result.prepend(tbl);



    }

    this.IcoToThumbs = function () {

        var desc2 = $('.srch-Description2');
        desc2.each(
function (index) {
    $(this).css('min-height', '20px');
    var url = $(this).nextAll('.srch-Metadata1:first').children('span:first').children('.srch-URL2').text();
    //alert($(this).nextAll('.srch-Metadata1:first').children('span:first').children('.srch-URL2').text());
    if (url.match(/^.+\.((docx)|(pptx)|(xps))$/) != null) {
        var img = $(this).prevAll('.srch-Icon:first').children('img')
        var urlImg = $("<a class='preview' rel=\"" + '/_layouts/SPThumbnailExtender/MobileGenericHandler.ashx?doc=' + url + "\" href=\"javascript:OpenDialog('http://srvmoss/_layouts/SPThumbnailExtender/ThumbSilverlight.aspx?doc=" + url + "')\" />")
        $(this).prevAll('.srch-Icon:first').append(urlImg);
        img.attr('src', '/_layouts/SPThumbnailExtender/MobileGenericHandler.ashx?doc=' + url);
        if (url.match(/^.+\.((pptx))$/) != null)
            img.css('width', 100);
        else
            img.css('width', 50);

        img.prependTo(urlImg);
    }
}
)

    };

    this.imagePreview = function () {
        /* CONFIG */

        xOffset = 100;
        yOffset = 30;

        // these 2 variable determine popup's distance from the cursor
        // you might want to adjust to get the right result

        /* END CONFIG */
        $("a.preview").hover(function (e) {
            this.t = this.title;
            this.title = "";
            var c = (this.t != "") ? "<br/>" + this.t : "";
            $("body").append("<p id='preview'><img src=\"" + this.rel + "\" alt='Image preview' />" + c + "</p>");
            $("#preview")
                        .css("top", (e.pageY - xOffset) + "px")
                        .css("left", (e.pageX + yOffset) + "px")
                        .fadeIn("fast");
        },
        function () {
            this.title = this.t;
            $("#preview").remove();
        });
        $("a.preview").mousemove(function (e) {
            $("#preview")
                        .css("top", (e.pageY - xOffset) + "px")
                        .css("left", (e.pageX + yOffset) + "px");
        });
    };
 

</script>


